<?php
namespace core\lib;
use core\lib\conf;
class route{
	public $controller;
	public $action;
	
	public function __construct(){
		// xxx.com/index/index
		/**
		 *1.隐藏index.php
		 *2.获取URL  参数部分
		 *3.返回对应控制器和方法 
		 */
		//p($_SERVER)只有域名下，$_SERVER['REQUEST_URI']='/'
		if(isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] != '/'){
			$path = $_SERVER['REQUEST_URI'];
			//trim() 函数移除字符串两侧的空白字符或其他预定义字符。
			$path_arr = explode('/',trim($path,'/'));
			if($path_arr[0] == 'index.php'){
				array_shift($path_arr);
			}
			if(isset($path_arr[0])){
				$this->controller = $path_arr[0];
				unset($path_arr[0]);
			}
			if(isset($path_arr[1])){
				$this->action = $path_arr[1];
				unset($path_arr[1]);
			}else{
				$this->action = conf::get('DEFAULT_ACTION','convention');
			}
			//url多余部分转换成GET
			//index/index/id/2
			$count = count($path_arr) + 2;
			$i = 2;
			while($i < $count){
				if(isset($path_arr[$i+1])){
					$_GET[$path_arr[$i]] = $path_arr[$i+1];
				}	
				$i = $i+2;
			}
		}else{
			$this->controller = conf::get('DEFAULT_CONTROLLER','convention');
			$this->action =  conf::get('DEFAULT_ACTION','convention');
		}
	}
}


?>